Imports PTT.CarRes.Data

Public Class ClassQueryInvCarDataType
    Public Function Add(ByVal InvCarDataType As QueryInvCarDataType, ByVal Strconn As String) As Boolean
        Dim ClsInvCarDataType As New ClassInvCarDataType
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarDataType.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvCarDataType
            .DataTypeID = InvCarDataType.DataTypeID
            .DataTypeName = InvCarDataType.DataTypeName
            .DataTypeDesc = InvCarDataType.DataTypeDesc
            .OtDay = InvCarDataType.OtDay
            .OtHoliday = InvCarDataType.OtHoliday
            .CostDay = InvCarDataType.CostDay
            .CostHoliday = InvCarDataType.CostHoliday
            .CostDriver = InvCarDataType.CostDriver
            .HumanNum = InvCarDataType.HumanNum
            .DataTypeStatus = InvCarDataType.DataTypeStatus
            .TypeId = InvCarDataType.TypeId
            ret = .USP_Save(Conn)
        End With
        ClsInvCarDataType.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvCarDataType As QueryInvCarDataType, ByVal Strconn As String) As Boolean
        Dim ClsInvCarDataType As New ClassInvCarDataType
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarDataType.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvCarDataType
            .DataTypeID = InvCarDataType.DataTypeID
            .Load(Conn)
            .DataTypeName = InvCarDataType.DataTypeName
            .DataTypeDesc = InvCarDataType.DataTypeDesc
            .OtDay = InvCarDataType.OtDay
            .OtHoliday = InvCarDataType.OtHoliday
            .CostDay = InvCarDataType.CostDay
            .CostHoliday = InvCarDataType.CostHoliday
            .CostDriver = InvCarDataType.CostDriver
            .HumanNum = InvCarDataType.HumanNum
            .DataTypeStatus = InvCarDataType.DataTypeStatus
            .TypeId = InvCarDataType.TypeId
            ret = .USP_Update(Conn)
        End With
        ClsInvCarDataType.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvCarDataType As QueryInvCarDataType, ByVal Strconn As String) As Boolean
        Dim ClsInvCarDataType As New ClassInvCarDataType
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarDataType.ConnectionOpen(Strconn)
        Dim ret As Boolean = False
        With ClsInvCarDataType
            .DataTypeID = InvCarDataType.DataTypeID
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        ClsInvCarDataType.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaDataTypeID As String = "", _
    Optional ByVal ParaDataTypeName As String = "", _
    Optional ByVal ParaDataTypeStatus As String = "", _
    Optional ByVal ParaTypeId As String = "", Optional ByVal Strconn As String = "") As QueryInvCarDataTypes
        Dim ClsInvCarDataType As New ClassInvCarDataType
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarDataType.ConnectionOpen(Strconn)
        Dim ret As QueryInvCarDataTypes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvCarDataType"
        If ParaDataTypeID & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(DataTypeID = " & ParaDataTypeID & ")"
        End If
        If ParaDataTypeName & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(DataTypeName like '%" & ParaDataTypeName & "%')"
        End If
        If ParaDataTypeStatus & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(DataTypeStatus like '%" & ParaDataTypeStatus & "%')"
        End If
        If ParaTypeId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(TypeId = " & ParaTypeId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvCarDataType
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvCarDataTypes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvCarDataType( _
                              .Item("DataTypeID") & "", _
                              .Item("DataTypeName") & "", _
                              .Item("DataTypeDesc") & "", _
                              .Item("OtDay") & "", _
                              .Item("OtHoliday") & "", _
                              .Item("CostDay") & "", _
                              .Item("CostHoliday") & "", _
                              .Item("CostDriver") & "", _
                              .Item("HumanNum") & "", _
                              .Item("DataTypeStatus") & "", _
                              .Item("TypeId") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvCarDataType.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaDataTypeID As String = "", _
    Optional ByVal ParaTypeId As String = "", Optional ByVal Strconn As String = "") As QueryInvCarDataTypes
        Dim ClsInvCarDataType As New ClassInvCarDataType
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvCarDataType.ConnectionOpen(Strconn)
        Dim ret As QueryInvCarDataTypes = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvCarDataType"
        If ParaDataTypeID & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(DataTypeID = " & ParaDataTypeID & ")"
        End If
        If ParaTypeId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(TypeId = " & ParaTypeId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvCarDataType
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvCarDataTypes

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvCarDataType( _
                              .Item("DataTypeID") & "", _
                              .Item("DataTypeName") & "", _
                              .Item("DataTypeDesc") & "", _
                              .Item("OtDay") & "", _
                              .Item("OtHoliday") & "", _
                              .Item("CostDay") & "", _
                              .Item("CostHoliday") & "", _
                              .Item("CostDriver") & "", _
                              .Item("HumanNum") & "", _
                              .Item("DataTypeStatus") & "", _
                              .Item("TypeId") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvCarDataType.ConnectionClose(Conn)
        Return ret
    End Function
End Class